package com.sanqing.action;

import java.util.List;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.sanqing.base.action.BaseAction;
import com.sanqing.po.Examine;
import com.sanqing.po.ExamineBatch;
import com.sanqing.service.ExamineBatchService;
import com.sanqing.service.ExamineService;
import com.sanqing.util.Page;
import com.sanqing.util.PageResult;

@Results({ @Result(name = "list", location = "/teacher/examineBatch/examineBatch-list.jsp"), 
	       @Result(name = "input", location = "/teacher/examineBatch/examineBatch-add.jsp"), 
	       @Result(name = "edit", location = "/teacher/examineBatch/examineBatch-edit.jsp"), 
	       @Result(name = "success", location = "examine-batch.action", type = "redirect")

})
public class ExamineBatchAction extends BaseAction<ExamineBatch> {

	private static final long serialVersionUID = 7795872940645683836L;
	private ExamineBatch examineBatch = new ExamineBatch();
	private int currentPage;
	@Autowired
	private ExamineBatchService examineBatchService;

	@Autowired
	private ExamineService examineService;

	/**
	 * 查询考试批次信息
	 */
	@Override
	public String list() throws Exception {
		Page page = new Page();
		page.setEveryPage(10);// 每页显示10条记录
		page.setCurrentPage(currentPage);// 设置当前页
		PageResult pageResult = examineBatchService.queryExamineBatchByPage(page, examineBatch);
		getRequest().setAttribute("pageResult", pageResult);
		return "list";
	}

	public String input() {
		List<Examine> examines = examineService.getList();
		getRequest().setAttribute("examines", examines);
		return "input";
	}

	/**
	 * 信息考试批次信息
	 * 
	 * @return
	 */
	public String add() {
		try {
			examineBatchService.add(examineBatch);
			this.addActionMessage("新增考试批次成功!");
		} catch (Exception e) {
			e.printStackTrace();
			this.addActionMessage("新增考试批次失败：" + e.getMessage());
		}
		return SUCCESS;
	}

	/**
	 * 更新考试批次信息
	 * 
	 * @return
	 */
	public String update() {
		try {
			examineBatchService.edit(examineBatch);
			this.addActionMessage("修改考试批次成功!");
		} catch (Exception e) {
			e.printStackTrace();
			this.addActionMessage("修改考试批次失败：" + e.getMessage());
		}
		return SUCCESS;
	}

	/**
	 * 删除信息
	 * 
	 * @return
	 */
	public String delete() {
		try {
			examineBatchService.delete(examineBatch.getId());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	@Override
	public ExamineBatch getModel() {
		return examineBatch;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
}
